package com.google.shop.product.controller.member;

import com.google.shop.product.common.utils.JwtUtils;
import com.google.shop.product.common.utils.R;
import com.google.shop.product.service.member.BuyerAddressService;
import com.google.shop.product.vo.member.BuyerAddressListVO;
import com.google.shop.product.vo.member.BuyerAddressVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/member"})
@RestController
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/controller/member/BuyerAddressController.class */
public class BuyerAddressController {
    private static final Logger log = LoggerFactory.getLogger(BuyerAddressController.class);
    @Autowired
    BuyerAddressService buyerAddressService;

    @GetMapping({"findBuyerAddressList"})
    public R findBuyerAddressList(String token) {
        if (token == null) {
            return R.error("token为空");
        }
        BuyerAddressListVO buyerAddressListVO = this.buyerAddressService.findBuyerAddressListBybuyerId(Integer.valueOf(JwtUtils.getMemberIdByJwtToken(token)));
        System.out.println("buyerAddressListVO:" + buyerAddressListVO);
        return R.ok(buyerAddressListVO);
    }

    @PostMapping({"/newBuyerAddress"})
    public R newBuyerAddress(@RequestBody BuyerAddressVO newAddressJSON) {
        System.out.println(newAddressJSON);
        if (newAddressJSON.getToken() == null) {
            return R.error("token为空");
        }
        try {
            this.buyerAddressService.saveBuyerAddress(newAddressJSON, Integer.valueOf(JwtUtils.getMemberIdByJwtToken(newAddressJSON.getToken())));
            return R.ok();
        } catch (Exception e) {
            return R.error("新增地址impl出现异常");
        }
    }

    @PostMapping({"/editBuyerAddress"})
    public R editBuyerAddress(@RequestBody BuyerAddressVO newAddressJSON) {
        System.out.println(newAddressJSON);
        if (newAddressJSON.getToken() == null) {
            return R.error("token为空");
        }
        try {
            this.buyerAddressService.editBuyerAddress(newAddressJSON, Integer.valueOf(JwtUtils.getMemberIdByJwtToken(newAddressJSON.getToken())));
            return R.ok();
        } catch (Exception e) {
            log.info(e + "");
            return R.error("修改地址impl出现异常");
        }
    }

    @PostMapping({"/findLineByAddressId"})
    public R findLineByAddressId(@RequestBody Integer addressId) {
        return R.ok(this.buyerAddressService.findLineById(addressId));
    }

    @GetMapping({"/findLineByAddressIdAndToken"})
    public R findLineByAddressIdAndToken(String token, Integer addressId) {
        if (token == null) {
            return R.error("token为空");
        }
        JwtUtils.getMemberIdByJwtToken(token);
        return R.ok(this.buyerAddressService.findLineById(addressId));
    }
}
